﻿using log4net;
using Mangox.Common;
using Mangox.Model.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Web.Http;

namespace MGXAPI.Controllers.API
{
    public class LogController : ApiController
    {
        static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// 公共日志
        /// </summary>
        /// <param name="logModel"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultComm Log(Log logModel)
        {
            if (logModel == null)
            {
                log.InfoFormat("ApiLog.Info：{0}", "参数为空");
                return new ResultComm()
                {
                    Message = "参数为空",
                    ResultType = ResultType.ParamError
                };
            }
            
            if (logModel.LogType == LogType.Info)
            {
                log.InfoFormat("ApiLog.Info：{0}",JsonCommon.ToJson<Log>(logModel));
            }
            else if (logModel.LogType == LogType.Error)
            {
                log.ErrorFormat("ApiLog.Error：{0}", JsonCommon.ToJson<Log>(logModel));
            }

            return new ResultComm()
            {
                Message = "ok",
                ResultType = ResultType.Success
            };
        }

    }
}
